<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户分享文件管理 - {{ user.username }}</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        h1, h2 {
            color: #333;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .action-buttons {
            display: flex;
            gap: 10px;
        }
        button, a.button {
            padding: 8px 12px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
        }
        .btn-cancel-share {
            background-color: #f44336;
            color: white;
        }
        .btn-back {
            background-color: #2196F3;
            color: white;
            margin-top: 20px;
        }
        .flash {
            padding: 10px;
            margin-bottom: 15px;
            border-radius: 4px;
        }
        .flash.success {
            background-color: #dff0d8;
            color: #3c763d;
        }
        .flash.error {
            background-color: #f2dede;
            color: #a94442;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>用户分享文件管理 - {{ user.username }}</h1>

        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="flash {{ category }}">{{ message }}</div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <h2>分享的文件列表</h2>
        {% if shared_files %}
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>文件名</th>
                        <th>大小</th>
                        <th>上传日期</th>
                        <th>分享过期时间</th>
                        <th>分享链接</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for file in shared_files %}
                        <tr>
                            <td>{{ file.id }}</td>
                            <td>{{ file.filename }}</td>
                            <td>{{ file.size }} 字节</td>
                            <td>{{ file.upload_date.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                            <td>{{ file.share_expiry.strftime('%Y-%m-%d %H:%M:%S') if file.share_expiry else '无过期时间' }}</td>
                            <td>
                                <a href="{{ url_for('shared_file', token=file.share_token, _external=True) }}" target="_blank">
                                    {{ url_for('shared_file', token=file.share_token, _external=True) }}
                                </a>
                            </td>
                            <td class="action-buttons">
                                <a href="{{ url_for('cancel_file_share', file_id=file.id) }}" class="button btn-cancel-share" onclick="return confirm('确定要取消该文件的分享吗？');">取消分享</a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% else %}
            <p>该用户没有分享的文件</p>
        {% endif %}

        <a href="{{ url_for('admin_dashboard') }}" class="button btn-back">返回管理员仪表板</a>
    </div>
</body>
</html>